//
//  ViewController.swift
//  MyTouTiao
//
//  Created by Yuri on 2018/3/15.
//  Copyright © 2018年 Yuri. All rights reserved.
//

import UIKit
import Moya
import PageMenu

class ViewController: UIViewController {
    
    //PageMenu
    var pageMenu : CAPSPageMenu!
    //PageMenu的Controllers
    var listControllers : [UITableViewController] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        getCategories()
    }
    
    func getCategories() {
        HttpCategory.getCategorys { (response) in
            self.listControllers = (response?.categories.map({
                let vc = self.storyboard?.instantiateViewController(withIdentifier: "SBID_NEWS_LIST") as! NewsListController
                vc.title = $0.title
                vc.categoryId = $0.id
                vc.parentNavigation = self.navigationController
                return vc
            }))!
            
            //PageMenu参数设置,设置为nil，采用默认配置
            let parameters: [CAPSPageMenuOption] = [
                //背景
                .scrollMenuBackgroundColor(UIColor.white),
                //控件的背景颜色
                .viewBackgroundColor(UIColor.white),
                .selectionIndicatorColor(UIColor.FromHEX("#ff3030")),
                .selectedMenuItemLabelColor(UIColor.FromHEX("#ff3030")),
                .unselectedMenuItemLabelColor(UIColor.FromHEX("#8a8a8a")),
                //PageMenu底部线条的颜色
                .bottomMenuHairlineColor(UIColor.FromHEX("#8a8a8a")),
                .menuItemFont(UIFont(name: "HelveticaNeue", size: 13.0)!),
                .menuHeight(40.0),
                .menuItemWidth(60.0),
                .centerMenuItems(true)
            ]
            
            //状态栏高度20，title bar的高度是44
            let frame = CGRect(x: 0, y: 20 + 44, width: self.view.frame.width, height: self.view.frame.height - 20 - 44)
            self.pageMenu = CAPSPageMenu(viewControllers: self.listControllers, frame: frame, pageMenuOptions: parameters)
            self.view.addSubview(self.pageMenu.view)
            
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

